﻿using System;
using nRoute.Components.Composition;

namespace Orktane.ScriptActionModel
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
    public class DefineScriptActionAttribute : MapScriptActionAttribute
    {
        readonly Type _implementingType;

        public DefineScriptActionAttribute(Type implementingType, string prefix, string title) 
            : base(prefix, title)
        {
            // basic checks
            if (implementingType == null) throw new ArgumentNullException("implementingType");
            EnsureIsScriptAction(implementingType);
                
            // we save
            _implementingType = implementingType;
        }

#region Overrides

        protected override IResourceLocator GetResourceLocator(Type targetType)
        {
            // and we get the resource locator, note the type switch
            return base.GetResourceLocator(_implementingType);
        }

#endregion

    }
}
